/*
 * Copyright (c) 2023.
 *
 * 作者：bmy
 * 邮箱：2271608011@qq.com
 * gitee：https://gitee.com/bmycode
 * github：https://github.com/helpcode
 *
 */

import * as monaco from 'monaco-editor';
import { themeConfig } from "@/stores/ThemeStore";
import { get } from 'svelte/store';

// 使用插件 vite-plugin-monaco-editor 简化了 MonacoEditor 的一些配置
// 原配置方法参考：https://github.com/microsoft/monaco-editor/blob/main/docs/integrate-esm.md#using-vite
export class MonacoEditor {

  public static conf = get(themeConfig)

  public static creatMonacoEditor(el: HTMLElement) {
    return monaco.editor.create(el, {
      value: '',
      language: 'json',
      formatOnPaste: true,
      formatOnType: true,
      tabSize: 2,
      fontSize: 16,
      contextmenu: false,
      automaticLayout: true,
      theme: "vs",
      lineNumbers: MonacoEditor.conf.lineNumbers,
      minimap: {
        enabled: Boolean(MonacoEditor.conf.minimap)
      }
    });
  }
}